package com.huanzhidadi.rabbitmq.rabbitmq;

import com.huanzhidadi.rabbitmq.cache.MyCache;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 接收订单延迟队列消息
 */
@Slf4j
@Component
public class OrderDelayedReceiver {

    @RabbitListener(queues = "order_delay_queue")
    public void aaa(String orderId) {
        Boolean payFlag = MyCache.orderPayMap.get(orderId);
        log.info("payFlag: {}", payFlag);
        if (true == payFlag) {
            log.info("订单 {} 付款成功。", orderId);
            return;
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat(("yyyy-MM-dd HH:mm:ss"));
        log.info("订单 {} 付款超时，订单取消, {}", orderId, dateFormat.format(new Date()));
    }
}
